home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE10 / TRANCAPS / LINE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  28KB  |  819 lines

  1.  
  2. #include <windows.h> 
  3. #include <windowsx.h> 
  4. #include "line.h" 
  5. #include "tapi.h"
  6.  
  7. #define BUFSIZE 256
  8. #define APIHIVERSION     0x00010028    /* 1.40 */
  9. #define APILOWVERSION    0x00010000    /* 1.0 */
  10. #define EXTHIVERSION     0x00010005    /* 1.5 */
  11. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  12. #define OWNER        0
  13. #define MONITOR      1
  14. #define MAX_CALL        3
  15. #define MAX_LINE        2
  16.  
  17.  
  18. #if defined (WIN32)
  19.     #define IS_WIN32 TRUE
  20. #else
  21.     #define IS_WIN32 FALSE
  22. #endif
  23.  
  24. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  25. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  26. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  27.  
  28. LPCTSTR lpszAppName = "lineGetTranslateCaps";
  29. LPCTSTR lpszTitle   = "lineGetTranslateCaps"; 
  30.  
  31. HINSTANCE hInst;   // current instance
  32. HWND hWnd;         // parent window handle
  33. HWND hListWnd;     // listbox
  34. HDC  hdc;
  35. TEXTMETRIC  tm ;
  36.  
  37. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  38.  
  39.  
  40. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.                       LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43.    MSG      msg;
  44.    WNDCLASS wc;
  45.  
  46.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  47.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  48.    wc.cbClsExtra    = 0;                      
  49.    wc.cbWndExtra    = 0;                      
  50.    wc.hInstance     = hInstance;              
  51.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  52.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  53.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  54.    wc.lpszMenuName  = lpszAppName;              
  55.    wc.lpszClassName = lpszAppName;              
  56.  
  57.    if ( IS_WIN95 )
  58.    {
  59.       if ( !RegisterWin95( &wc ) )
  60.          return( FALSE );
  61.    }
  62.    else if ( !RegisterClass( &wc ) )
  63.       return( FALSE );
  64.  
  65.    hInst = hInstance; 
  66.  
  67.    hWnd = CreateWindow( lpszAppName, 
  68.                         lpszTitle,    
  69.                         WS_OVERLAPPEDWINDOW, 
  70.                         CW_USEDEFAULT, 0, 
  71.                         CW_USEDEFAULT, 0,  
  72.                         NULL,              
  73.                         NULL,              
  74.                         hInstance,         
  75.                         NULL               
  76.                       );
  77.  
  78.    if ( !hWnd ) 
  79.       return( FALSE );
  80.  
  81.    ShowWindow( hWnd, nCmdShow ); 
  82.    UpdateWindow( hWnd );         
  83.  
  84.    while( GetMessage( &msg, NULL, 0, 0) )   
  85.    {
  86.       TranslateMessage( &msg ); 
  87.       DispatchMessage( &msg );  
  88.    }
  89.  
  90.    return( msg.wParam ); 
  91. }
  92.  
  93.  
  94. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  95. {
  96.     WNDCLASSEX wcex;
  97.  
  98.    wcex.style         = lpwc->style;
  99.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  100.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  101.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  102.    wcex.hInstance     = lpwc->hInstance;
  103.    wcex.hIcon         = lpwc->hIcon;
  104.    wcex.hCursor       = lpwc->hCursor;
  105.    wcex.hbrBackground = lpwc->hbrBackground;
  106.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  107.    wcex.lpszClassName = lpwc->lpszClassName;
  108.  
  109.    // Added elements for Windows 95.
  110.    //...............................
  111.    wcex.cbSize = sizeof(WNDCLASSEX);
  112.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  113.                             IMAGE_ICON, 16, 16,
  114.                             LR_DEFAULTCOLOR );
  115.             
  116.    return RegisterClassEx( &wcex );
  117. }
  118.  
  119. #define CONFCALL    1
  120. #define CONSULT      2
  121.  
  122. enum CallState
  123. {
  124.     Idle,
  125.     Offering,
  126.     Accepted,
  127.     Dialtone,
  128.     Dialing,
  129.     Ringback,
  130.     Busy,
  131.     Special,
  132.     Connected,
  133.     Proceeding,
  134.     Conferenced,
  135.     Onholdconf,
  136.     Disconnected,
  137.     Unknown
  138. };
  139.  
  140. typedef struct tagMYINFO      // general application information
  141. {
  142.     HLINEAPP lineApp;         // instance handle TAPI gives back to us                                                                              through lineInitialize()
  143.     DWORD dwNumDevices;       // number of available devices
  144.     DWORD dwAPIVersion;       // API version the line supports
  145.      DWORD dwExtVersion;           // extended version
  146.     char szLocation[128];     // location        
  147.      char szCallingCard[128];  // calling card being used
  148.     char szAreaCode[4];       // area code       
  149.     char szCountry[128];      // calling card being used
  150. } MYINFO;
  151.  
  152. typedef struct tagLINEINFO  // information on an open line
  153. {
  154.     DWORD dwNumAddress;     // number of available addresses on the line 
  155.     HLINE hLine;            // handle to the line as returned by lineOpen 
  156.      DWORD dwLineID;         // the line ID of this line
  157.     char  szLineName[128];  // the line's name 
  158.  
  159. } MYLINEINFO;
  160.  
  161. typedef struct tagMYCALLINFO  //information on a call                     
  162. {
  163.     
  164. DWORD       eCallState;    // TAPI's line call State, set as user-defined enums
  165. DWORD      dwRequestID;   // requestID returned by async TAPI functions lineMakeCall/lineDropCall
  166. DWORD      dwAddressID;   // the originating address ID of the call being made 
  167. LPCSTR     lpszAddress;    
  168. HLINE     hLine;         // handle to the line 
  169. HCALL        hCall;         // handle to the call 
  170.    
  171. char szDialString[TAPIMAXDESTADDRESSSIZE];  //phone number being dialed
  172. char szDialStringOriginal[TAPIMAXDESTADDRESSSIZE];
  173. char szDialStringCanonical[TAPIMAXDESTADDRESSSIZE];
  174. char szCalledParty[TAPIMAXCALLEDPARTYSIZE]; // name of the party
  175. DWORD dwTranslateResults;
  176.         
  177. } MYCALLINFO;
  178.  
  179. enum CallAction     // Declare enum type CallAction (used in lineSetAppSpecific)
  180. {
  181.    HOLD,            // hold the call
  182.    TRANSFER,        // transfer the call
  183.    REDIRECT,        // redirect the call
  184.    DROP,            // drop the call
  185.    PARK             // park the call
  186. }; 
  187.  
  188. MYINFO myInfo;          //instance of MYINFO structure
  189. MYLINEINFO myLineInfo[MAX_LINE];  //instance of MYLINEINFO structure
  190. MYCALLINFO myCallInfo[MAX_CALL]; //array of MYCALLINFO strcuture
  191.  
  192. LONG lRet;        //return code
  193. char buf[BUFSIZE];    // buffer for debug message
  194.  
  195. DWORD dwLineID = 0;
  196. DWORD i;
  197. LINEEXTENSIONID        ext_id;
  198. LINEDEVCAPS            *plineDevCaps;
  199. LINEADDRESSCAPS        *plineAddressCaps;
  200. LINEADDRESSSTATUS     *plineAddressStat;
  201. LINECALLINFO            *plineCallInfo;
  202. LINECALLSTATUS         *plineCallStatus;
  203. LINECALLLIST            *plineCallList;
  204. LINEDEVSTATUS           *plineDevStatus;
  205. LINETRANSLATECAPS       *plineTranslateCaps;
  206. LINETRANSLATEOUTPUT  *plineTranslateOutput;
  207. LINECALLPARAMS           *plineCallParams;
  208. LINEDEVSTATUS           *plineDevStatus;
  209. LINEFORWARDLIST        *plineForwardList;
  210. LINETRANSLATECAPS       *plineTranslateCaps;
  211. LINEREQMAKECALL       lineReqMakeCall;
  212. VARSTRING               *pDeviceConfig;
  213. VARSTRING               *pDeviceId;
  214. VARSTRING               *pNonDirAddress;
  215.  
  216. LPLINELOCATIONENTRY  lineLocEntry;
  217. LPLINECARDENTRY        lineCardEntry;
  218. LINECOUNTRYLIST         *plineCountryList;
  219. LPLINECOUNTRYENTRY   lineCE;
  220.  
  221. LPSTR                lpData;
  222. DWORD                dwLineStates, dwAddressStates;
  223.  
  224. HICON                hIcon = NULL;        //used in lineGetID();
  225. DWORD                dwNumRings;    //used in lineGetTranslateCaps();
  226. HCALL                hConsultCall; //handle to consultation linePrepareAddToConference, SetupConference
  227. HCALL                hConfCall; //handle to consultation linePrepareAddToConference, SetupConference   
  228. HCALL                hParkedCall;
  229.  
  230. DWORD                dwCompletionID;  //used in lineCompleteCall()
  231.  
  232. char                szName[128];
  233. char                szNumber[128];
  234. char                szDigits[128];
  235. char                szDevConfig[128];
  236.  
  237. LONG lRet;
  238. char buf[BUFSIZE];
  239.  
  240. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  241. {
  242.    switch( uMsg )
  243.    {
  244.       case WM_COMMAND :
  245.          switch( LOWORD( wParam ) )
  246.          {
  247.             case IDM_RUN :
  248.                //get translation capabilities 
  249.                //...............................................
  250.                plineTranslateCaps = (LINETRANSLATECAPS *) calloc (1,
  251.                                        sizeof(LINETRANSLATECAPS) + 1000);
  252.                plineTranslateCaps->dwTotalSize = sizeof(LINETRANSLATECAPS) +                 
  253.                                                        1000;
  254.             
  255.                lRet = lineGetTranslateCaps(myInfo.lineApp, myInfo.dwAPIVersion,                      
  256.                                           plineTranslateCaps);
  257.                
  258.                if (lRet == 0)                        
  259.                {
  260.                   wsprintf (buf, "lineGetTranslateCaps succeeded!");
  261.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  262.                   lineLocEntry = (LPLINELOCATIONENTRY)  
  263.                                ((LPSTR)(plineTranslateCaps) + plineTranslateCaps                         
  264.                                                         ->dwLocationListOffset);
  265.              
  266.                   for (i = 0; i < plineTranslateCaps->dwNumLocations; ++i)
  267.                   {
  268.                      if (lineLocEntry[i].dwPermanentLocationID !=                       
  269.                                         plineTranslateCaps->dwCurrentLocationID)
  270.                         continue;
  271.  
  272.                      strncpy(myInfo.szLocation,(LPSTR)(plineTranslateCaps) +                          
  273.                              lineLocEntry->dwLocationNameOffset,
  274.                              lineLocEntry->dwLocationNameSize);
  275.                      strcpy(buf, myInfo.szLocation);
  276.                      strcat( buf, " is the location." );
  277.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  278.  
  279.                      strncpy(myInfo.szAreaCode, (LPSTR)(plineTranslateCaps) +                          
  280.                              lineLocEntry[i].dwCityCodeOffset,
  281.                              lineLocEntry[i].dwCityCodeSize);
  282.                      strcpy(buf, myInfo.szLocation);
  283.                      strcat( buf, " is the area code." );
  284.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  285.                  }                  
  286.                         
  287.                  for (i = 0; i < plineTranslateCaps->dwNumCards; ++i)
  288.                  {
  289.                      if (lineCardEntry[i].dwPermanentCardID !=                           
  290.                                    plineTranslateCaps->dwCurrentPreferredCardID)
  291.                         continue;
  292.  
  293.                     lineCardEntry = (LPLINECARDENTRY)((LPSTR)(plineTranslateCaps)   
  294.                                      + plineTranslateCaps->dwCardListOffset);
  295.                     strncpy(myInfo.szCallingCard,(LPSTR)(plineTranslateCaps) +                         
  296.                             lineCardEntry[i].dwCardNameOffset,
  297.                             lineCardEntry[i].dwCardNameSize);
  298.                     strcpy(buf, myInfo.szLocation);
  299.                     strcat( buf, " is the calling card." );
  300.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  301.                  }
  302.                                             
  303.                  //set the current location in the telphon.ini file
  304.                  //.................................................
  305.                  lRet = lineSetCurrentLocation(myInfo.lineApp,  
  306.                               plineTranslateCaps->dwCurrentLocationID);
  307.                  if (lRet != 0)
  308.                  {
  309.                      wsprintf (buf, "lineSetCurrentLocation failed, err=x%lx", 
  310.                                lRet);
  311.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;      
  312.                      lineError(lRet);
  313.                  }
  314.             }
  315.             else 
  316.             {
  317.                  wsprintf (buf, "lineGetTranslateCaps failed, err=x%lx", lRet);
  318.                  lineError(lRet);
  319.             }
  320.          
  321.             free (plineTranslateCaps);
  322.             break;
  323.          
  324.             case IDM_ABOUT :
  325.             {
  326.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  327.                break;
  328.             }
  329.  
  330.             case IDM_EXIT :
  331.             {
  332.                for (i = 0; i < myInfo.dwNumDevices; i++)
  333.                        lineClose(myLineInfo[i].hLine);
  334.                     lineShutdown(myInfo.lineApp);
  335.                DestroyWindow( hWnd );
  336.                break;
  337.             }
  338.             }                  
  339.                  
  340.          break;
  341.  
  342.       case WM_CREATE :
  343.       {
  344.          hdc = GetDC (hWnd) ;
  345.          GetTextMetrics (hdc, &tm) ;
  346.          ReleaseDC (hWnd, hdc) ;
  347.  
  348.          hListWnd = CreateWindowEx( 0, "listbox", 
  349.                         " ",    
  350.                         WS_CHILD | WS_VISIBLE,  
  351.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  352.                         tm.tmAveCharWidth * 16 +
  353.                                    GetSystemMetrics (SM_CXVSCROLL), 
  354.                         tm.tmHeight * 5,  
  355.                         hWnd,              
  356.                         NULL,              
  357.                         hInst,         
  358.                         NULL               
  359.                         );
  360.  
  361.          
  362.          //lineInitialize
  363.             //...............................................
  364.          lRet = lineInitialize(&myInfo.lineApp, hInst, lineCallback, NULL, &myInfo.dwNumDevices);
  365.          if (lRet == 0) 
  366.          {
  367.             wsprintf (buf, "lineInitialize suceeded!");
  368.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  369.            }
  370.          else 
  371.           {
  372.                wsprintf ( buf,"lineInitialize failed, err=x%lx",lRet);
  373.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  374.                lineError(lRet);
  375.                break;
  376.          }                    
  377.          
  378.          //lineNegotiateAPIVersion
  379.           //...............................................
  380.          lRet = lineNegotiateAPIVersion(myInfo.lineApp, 0, APILOWVERSION, APIHIVERSION, 
  381.                                            &myInfo.dwAPIVersion, &ext_id);
  382.          if (lRet == 0)                        
  383.          {
  384.             wsprintf (buf, "lineNegotiateAPIVersion suceeded!");
  385.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  386.          }
  387.          else 
  388.           {
  389.                wsprintf (buf, "lineNegotiateAPIVersion failed, err=x%lx",
  390.                            lRet);
  391.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  392.                lineError(lRet);
  393.                lineShutdown (myInfo.lineApp);
  394.             break;
  395.          }
  396.  
  397.           //lineNegotiateExtVersion
  398.           //...............................................
  399.          lRet = lineNegotiateExtVersion(myInfo.lineApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  400.                                            EXTHIVERSION, &myInfo.dwExtVersion);
  401.          if (lRet == 0)                        
  402.          {
  403.             wsprintf (buf, "lineNegotiateExtVersion suceeded!");
  404.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  405.  
  406.          }
  407.           else 
  408.           {
  409.                wsprintf (buf, "lineNegotiateExtVersion failed, err=x%lx",
  410.                      lRet);
  411.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  412.               lineError(lRet);
  413.       
  414.          }
  415.  
  416.           //lineGetDevCaps
  417.           //for each line device, get capabilities until we find one that supports
  418.          //interactive voice 
  419.           //...............................................
  420.          plineDevCaps = (LINEDEVCAPS *) calloc (1, sizeof(LINEDEVCAPS)+1000);
  421.          plineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1000;
  422.          for (i = 0; i < myInfo.dwNumDevices; i++)
  423.          {
  424.             lineGetDevCaps(myInfo.lineApp, i, myInfo.dwAPIVersion, 0, plineDevCaps);
  425.             if (plineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) 
  426.             {
  427.                
  428.                myLineInfo[i].dwNumAddress = plineDevCaps->dwNumAddresses;
  429.                   myLineInfo[i].dwLineID = i;
  430.                    if (plineDevCaps->dwLineNameSize > 0)
  431.                           strcpy(myLineInfo[i].szLineName,((LPSTR)(plineDevCaps)+plineDevCaps->dwLineNameOffset));
  432.              }
  433.           }
  434.  
  435.          //lineOpen
  436.           //................................................................
  437.           lRet = lineOpen(myInfo.lineApp,myLineInfo[OWNER].dwLineID,&myLineInfo[OWNER].hLine,
  438.                            myInfo.dwAPIVersion,0,(DWORD)lineCallback, LINECALLPRIVILEGE_NONE,
  439.                             LINEMEDIAMODE_DATAMODEM, NULL);
  440.           if (lRet == 0)
  441.           {
  442.             wsprintf (buf, "lineOpen suceeded!");
  443.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;         }
  444.            else 
  445.            {
  446.                wsprintf ( buf,"lineOpen failed, err=x%lx", lRet);
  447.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  448.                lineError(lRet);
  449.           }
  450.        
  451.          break;
  452.       }
  453.       
  454.       case WM_SIZE:
  455.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  456.          break;
  457.  
  458.       case WM_DESTROY :
  459.               PostQuitMessage(0);
  460.               break;
  461.  
  462.       default :
  463.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  464.    }
  465.  
  466.    return( 0L );
  467. }
  468.  
  469.  
  470.  
  471.  
  472. /****************************************************************************
  473.     FUNCTION: lineCallback
  474.     PURPOSE:  callback function handles line events
  475. ****************************************************************************/
  476. LRESULT CALLBACK lineCallback (DWORD dwDevice, DWORD dwMsg,
  477.                                        DWORD dwCallbackInst, DWORD dwParam1,
  478.                                        DWORD dwParam2,DWORD dwParam3)
  479. {
  480.    switch (dwMsg)
  481.    {
  482.       case LINE_CALLSTATE:
  483.        {
  484.             for (i = 0; i < MAX_CALL; i++)
  485.            {
  486.                 if (dwDevice = (DWORD) myCallInfo[i].hCall) 
  487.                  switch (dwParam1)
  488.                  {
  489.                     case LINECALLSTATE_IDLE:
  490.                         myCallInfo[i].eCallState = Idle;
  491.                   break;
  492.                     
  493.                     case LINECALLSTATE_OFFERING:
  494.                   myCallInfo[i].eCallState = Offering;
  495.                   break;
  496.                                    
  497.                     case LINECALLSTATE_ACCEPTED:
  498.                         myCallInfo[i].eCallState = Accepted;
  499.                         break;
  500.                     
  501.                     case LINECALLSTATE_DIALTONE:
  502.                         myCallInfo[i].eCallState = Dialtone;
  503.                   break;
  504.                     
  505.                     case LINECALLSTATE_DIALING:
  506.                         myCallInfo[i].eCallState = Dialing;
  507.                         break;
  508.                   
  509.                   case LINECALLSTATE_RINGBACK:
  510.                         myCallInfo[i].eCallState = Ringback;
  511.                         break;
  512.             
  513.                     case LINECALLSTATE_BUSY:
  514.                         myCallInfo[i].eCallState = Busy;
  515.                         break;
  516.             
  517.                     case LINECALLSTATE_SPECIALINFO:
  518.                         myCallInfo[i].eCallState = Special;
  519.                        break;
  520.             
  521.                     case LINECALLSTATE_CONNECTED:
  522.                        myCallInfo[i].eCallState = Connected;
  523.                   break;
  524.  
  525.                     case LINECALLSTATE_PROCEEDING:
  526.                         myCallInfo[i].eCallState = Proceeding;
  527.                        break;
  528.             
  529.                     case LINECALLSTATE_CONFERENCED:
  530.                         myCallInfo[i].eCallState = Conferenced;
  531.                        break;
  532.             
  533.                     case LINECALLSTATE_ONHOLDPENDCONF:
  534.                         break;
  535.                 
  536.                case LINECALLSTATE_DISCONNECTED:
  537.                         myCallInfo[i].eCallState = Disconnected;
  538.                        break;
  539.             
  540.                     case LINECALLSTATE_UNKNOWN:
  541.                         myCallInfo[i].eCallState = Unknown;
  542.                        break;
  543.        
  544.              }
  545.           }
  546.        }
  547.  
  548.        case LINE_MONITORMEDIA:
  549.            break;
  550.  
  551.        case LINE_MONITORDIGITS:
  552.           break;
  553.  
  554.          case LINE_MONITORTONE:
  555.           break;
  556.    
  557.        //error handling for functions completed asynchronously
  558.         //.....................................................
  559.        case LINE_REPLY:
  560.         {
  561.             for (i = 0; i < MAX_CALL; i++)
  562.            {
  563.                 if (dwParam1 = myCallInfo[i].dwRequestID)
  564.                {
  565.                    if (dwParam2 != 0)
  566.                    {
  567.                        lineError((LONG) dwParam2);
  568.                        break;
  569.                    }
  570.                }
  571.            }
  572.         break;
  573.         }
  574.  
  575.         case LINE_GENERATE:
  576.           break;
  577.      
  578.        case LINE_REQUEST:
  579.          break;
  580.  
  581.         case LINE_GATHERDIGITS:
  582.            break;
  583.    }
  584.  
  585.    return (TRUE);
  586.  
  587.  
  588. /****************************************************************************
  589.     FUNCTION: lineError
  590.     PURPOSE:  line error messages
  591. ****************************************************************************/
  592. void lineError (LONG lrc)
  593. {
  594.  switch (lrc) {
  595.     case LINEERR_INVALAPPHANDLE:
  596.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  597.        break;
  598.     case LINEERR_BADDEVICEID:
  599.        MessageBox (hWnd,"The specified line device ID is out of range.", "", 
  600.                    MB_OK);
  601.        break;
  602.     case LINEERR_INCOMPATIBLEAPIVERSION:
  603.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  604.        break;
  605.     
  606.     case LINEERR_ADDRESSBLOCKED:
  607.        MessageBox (hWnd, "Address was blocked.", "", MB_OK);
  608.        break;
  609.  
  610.     case LINEERR_BEARERMODEUNAVAIL:
  611.        MessageBox (hWnd, "Bearer Mode Unavailable.", "", MB_OK);
  612.        break;
  613.  
  614.     case LINEERR_CALLUNAVAIL:
  615.        MessageBox (hWnd, "Call appearances in use..", "", MB_OK);
  616.        break;
  617.  
  618.     case LINEERR_INUSE:
  619.        MessageBox (hWnd, "Line in Use.", "", MB_OK);
  620.        break;
  621.     
  622.     case LINEERR_INVALADDRESS:
  623.        MessageBox (hWnd, "Invalid Address.", "", MB_OK);
  624.        break;
  625.  
  626.     case LINEERR_INVALADDRESSID:
  627.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  628.        break;
  629.  
  630.     case LINEERR_INVALCALLPARAMS:
  631.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  632.        break;
  633.      
  634.     case LINEERR_INCOMPATIBLEEXTVERSION:
  635.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  636.        break;
  637.     case LINEERR_NOMEM:
  638.        MessageBox (hWnd, "No memory","", MB_OK);
  639.        break;
  640.     case LINEERR_NODRIVER:
  641.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  642.        break;
  643.     case LINEERR_RESOURCEUNAVAIL:
  644.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  645.        break;
  646.     case LINEERR_INVALPRIVSELECT:
  647.        MessageBox (hWnd, "Requested invalid priviledges", "", MB_OK);
  648.        break;
  649.     case LINEERR_INVALMEDIAMODE:
  650.        MessageBox (hWnd, "Requested invalid media mode", "", MB_OK);
  651.        break;
  652.     case LINEERR_LINEMAPPERFAILED:
  653.        MessageBox (hWnd, "Line mapper failed", "", MB_OK);
  654.        break;
  655.     case LINEERR_INVALPOINTER:
  656.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  657.                    "", MB_OK);
  658.        break;
  659.     case LINEERR_OPERATIONFAILED:
  660.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  661.        break;
  662.     case LINEERR_INVALLINEHANDLE:
  663.        MessageBox (hWnd, "Invalid line handle", "", MB_OK);
  664.        break;
  665.     case LINEERR_INVALCALLHANDLE:
  666.        MessageBox (hWnd, "Invalid call handle", "", MB_OK);
  667.        break;
  668.     case LINEERR_INVALCALLSELECT:
  669.        MessageBox (hWnd, "Invalid call selection", "", MB_OK);
  670.        break;
  671.     case LINEERR_NODEVICE:
  672.        MessageBox (hWnd, "No associated device for given class",
  673.                    "", MB_OK);
  674.        break;
  675.     case LINEERR_OPERATIONUNAVAIL:
  676.        MessageBox (hWnd, "The operation is unavailable",
  677.                    "", MB_OK);
  678.        break;
  679.     case LINEERR_INVALPARAM:
  680.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  681.        break; 
  682.  
  683.     case LINEERR_TARGETNOTFOUND:
  684.         MessageBox(hWnd, "Target Not Found", "", MB_OK);
  685.        break; 
  686.  
  687.    case LINEERR_NOREQUEST:
  688.       MessageBox(hWnd, "No outstanding Assisted Telephony requests.", "", MB_OK);
  689.        break; 
  690.    }
  691. }
  692.  
  693. LRESULT CALLBACK Dial ( HWND hDlg,           // window handle of the dialog box
  694.                         UINT message,        // type of message
  695.                         WPARAM wParam,       // message-specific information
  696.                         LPARAM lParam)
  697. {
  698.    switch (message) 
  699.    {
  700.        case WM_INITDIALOG:  // message: initialize dialog box
  701.                return (TRUE);
  702.  
  703.        case WM_COMMAND:                              // message: received a command
  704.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  705.          {
  706.             GetDlgItemText(hDlg, IDC_NAME, szName, 128);
  707.                 GetDlgItemText(hDlg, IDC_NUMBER, szNumber, 128);
  708.                                       
  709.  
  710.                 // put up a dialog box to obtain a string to dial from the user
  711.                //...........................................................
  712.                strcpy(myCallInfo[0].szDialStringOriginal, szNumber); 
  713.                
  714.                //allocate buffer for the LINEADDRESSCAPS strucuture 
  715.                //...................................................
  716.                plineTranslateOutput = (LINETRANSLATEOUTPUT *) calloc (1, sizeof(LINETRANSLATEOUTPUT)+1000);
  717.             plineTranslateOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT) + 1000;
  718.               
  719.                // translate the Address to a dialable address and Canonical address
  720.                //.....................................................................
  721.                lRet = lineTranslateAddress(myInfo.lineApp, myLineInfo[OWNER].dwLineID, myInfo.dwAPIVersion,
  722.                                            myCallInfo[0].szDialStringOriginal, 0, 0, plineTranslateOutput);
  723.                               
  724.                if (lRet == 0)
  725.                {
  726.                        
  727.                    strncpy(myCallInfo[0].szDialString, (LPSTR)(plineTranslateOutput)
  728.                             + plineTranslateOutput->dwDialableStringOffset,
  729.                              plineTranslateOutput->dwDialableStringSize); 
  730.     
  731.                     strncpy(myCallInfo[0].szDialStringCanonical,(LPSTR)(plineTranslateOutput) 
  732.                             + plineTranslateOutput->dwDisplayableStringOffset,
  733.                             plineTranslateOutput->dwDisplayableStringSize); 
  734.                                            
  735.                    myCallInfo[0].dwTranslateResults = plineTranslateOutput->dwTranslateResults;
  736.                 }
  737.  
  738.                else 
  739.                {
  740.                     wsprintf ( buf,"lineTranslateAddress failed, err=x%lx", lRet);
  741.                     lineError(lRet);
  742.                    break;
  743.             }
  744.            
  745.                //lineMakeCall
  746.                //................................................................
  747.                           
  748.                plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  749.             plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  750.  
  751.                plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  752.                plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  753.                plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  754.                plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  755.                plineCallParams->dwAddressID    = 0;
  756.                plineCallParams->dwMinRate    = 1200;
  757.                plineCallParams->dwMaxRate    = 2400;
  758.                             
  759.                lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  760.                                       myCallInfo[0].szDialString ,0,  plineCallParams);
  761.            
  762.             if (lRet > 0)
  763.                {
  764.                wsprintf (buf, "lineMakeCall suceeded!");
  765.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;               
  766.                    myCallInfo[0].dwRequestID = lRet;
  767.                 }
  768.             else 
  769.                {
  770.                    wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  771.                     lineError(lRet);
  772.                    break;
  773.             }
  774.             
  775.             EndDialog(hDlg, TRUE);        // Exit the dialog
  776.             return (TRUE);
  777.          }
  778.  
  779.             if (   LOWORD(wParam) == IDCANCEL)         // "OK" box selected?
  780.          {
  781.             EndDialog(hDlg, TRUE);        // Exit the dialog
  782.             return (TRUE);
  783.          }
  784.          break;
  785.  
  786.  
  787.    }
  788.  
  789.    return (FALSE); 
  790. }
  791.  
  792.  
  793. LRESULT CALLBACK About( HWND hDlg,           
  794.                         UINT message,        
  795.                         WPARAM wParam,       
  796.                         LPARAM lParam)
  797. {
  798.    switch (message) 
  799.    {
  800.        case WM_INITDIALOG: 
  801.                return (TRUE);
  802.  
  803.        case WM_COMMAND:                              
  804.                if (   LOWORD(wParam) == IDOK         
  805.                    || LOWORD(wParam) == IDCANCEL)    
  806.                {
  807.                        EndDialog(hDlg, TRUE);        
  808.                        return (TRUE);
  809.                }
  810.                break;
  811.    }
  812.  
  813.    return (FALSE); 
  814. }
  815.  
  816.  
  817.  
  818.